<!DOCTYPE html>
<html class="loginHtml">
<head>
	<meta charset="utf-8">
	<title>登录--layui后台管理模板 2.0</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="icon" href="../../favicon.ico">
	<link rel="stylesheet" href="../../layui/css/layui.css" media="all" />
	
</head>
<body class="loginBody">
	<button type="button" class="layui-btn" id="test1">
        <i class="layui-icon">&#xe67c;</i>上传图片
    </button>
    <div style="width: 1000px; height: 500px;">
        <img src="" id="img" alt="">
    </div>
	<script type="text/javascript" src="../../layui/layui.js"></script>
	<script>
        layui.use(['upload','jquery'], function () {
                var upload = layui.upload;
                var $=layui.$;

                upload.render({
                    elem: '#test1' //绑定元素
                    , url: 'http://localhost:8080/api/upload' //上传接口
                    , done: function (res) {
                        //上传完毕回调
                        console.log(res);
                    }
                    , error: function () {
                        //请求异常回调
                        console.log(error);
                    }
                    ,auto: false //选择文件后不自动上传
                    ,choose: function(obj){
                        //将每次选择的文件追加到文件队列
                        var files = obj.pushFile();
                        
                        //预读本地文件，如果是多文件，则会遍历。(不支持ie8/9)
                        obj.preview(function(index, file, result){
                        
     
                        //这里还可以做一些 append 文件列表 DOM 的操作
                        $('#img').attr('src',result);
                        });
                    }
                })
                
            })
    </script>
	
</body>
</html>